/*
 * $Log: Correspondence.java,v $
 * Revision 1.13  2008/08/14 17:43:12  pchapman
 * divested letter template from correspondence
 *
 * Revision 1.12  2008/08/14 00:53:50  pchapman
 * *** empty log message ***
 *
 * Revision 1.11  2008/08/13 23:09:43  pchapman
 * removed letter (template) from Correspondence
 *
 * Revision 1.10  2008/08/12 00:52:16  pchapman
 * bugs and correspondence updates
 *
 * Revision 1.9  2008/07/30 23:35:17  bgearring
 * added discardedCorrespondence
 *
 */

package com.redside.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * @author PCHAPMAN
 * 
 */
@Entity
@Table(name = "correspondence")
public class Correspondence extends BaseObject implements java.io.Serializable {

	private static final long serialVersionUID = -76273678111089059L;
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "correspondence_id")
	private Long id;

	@ManyToOne
    @JoinColumn(name = "complaint_id")
	private Complaint complaint;
	
	@Column(name = "corr_type_id")
	private Long corrTypeLkpId;
	
	@Temporal(TemporalType.TIMESTAMP)
    @Column(name = "generated_date")
	private Date generatedDate;
	
	@Temporal(TemporalType.TIMESTAMP)
    @Column(name = "sent_date")
	private Date sentDate;
	
	@Temporal(TemporalType.TIMESTAMP)
    @Column(name = "hardcopy_date")
	private Date hardCopyDate;
	
	@Column(name="letter_text", length=5000)
	private String letterText = "";
	
	@Column(name="notes", length=1000)
	private String notes = "";
	
	@Column(name="title", length=250)
	private String title = "";
	
	@Column(name = "discarded_correspondence", nullable = false)
	private boolean discardedCorrespondence;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "correspondence_id")
	private List<Email> emails = new ArrayList<Email>();

	public Correspondence() {
	}

	public Correspondence(Complaint complaint, 
			Date generatedDate, Date sentDate, 
			String letterText, String notes,
			List<Email> emails) {
		this.complaint = complaint;
		this.generatedDate = generatedDate;
		this.sentDate = sentDate;
		this.letterText = letterText;
		this.notes = notes;
		this.emails = emails;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Complaint getComplaint() {
		return this.complaint;
	}

	public void setComplaint(Complaint complaint) {
		this.complaint = complaint;
	}

	public Long getCorrTypeLkpId() {
        return corrTypeLkpId;
    }

    public void setCorrTypeLkpId(Long corrTypeLkpId) {
        this.corrTypeLkpId = corrTypeLkpId;
    }

    public Date getGeneratedDate() {
		return this.generatedDate;
	}

	public void setGeneratedDate(Date generatedDate) {
		this.generatedDate = generatedDate;
	}

	public Date getSentDate() {
		return this.sentDate;
	}

	public void setSentDate(Date sentDate) {
		this.sentDate = sentDate;
	}

	public Date getHardCopyDate() {
        return hardCopyDate;
    }

    public void setHardCopyDate(Date hardCopyDate) {
        this.hardCopyDate = hardCopyDate;
    }

    public String getLetterText() {
		return this.letterText;
	}

	public void setLetterText(String letterText) {
		this.letterText = letterText;
	}

	public String getNotes() {
		return this.notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public List<Email> getEmails() {
		return this.emails;
	}

	public void setEmails(List<Email> emails) {
		this.emails = emails;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public boolean isDiscardedCorrespondence() {
		return discardedCorrespondence;
	}

	public void setDiscardedCorrespondence(boolean discardedCorrespondence) {
		this.discardedCorrespondence = discardedCorrespondence;
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof Correspondence)) {
			return false;
		}
		Correspondence rhs = (Correspondence) object;
		return new EqualsBuilder().append(
				this.id, rhs.id).append(this.title, rhs.title).append(
				this.generatedDate, rhs.generatedDate).append(
				this.discardedCorrespondence, rhs.discardedCorrespondence)
				.append(this.sentDate, rhs.sentDate).append(this.emails,
						rhs.emails).append(this.letterText, rhs.letterText)
				.append(this.hardCopyDate, rhs.hardCopyDate).append(
						this.corrTypeLkpId, rhs.corrTypeLkpId).append(
						this.notes, rhs.notes).append(this.complaint, rhs.complaint)
				.isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(380748489, -421670979).append(this.id).append(this.title).append(
				this.generatedDate).append(this.discardedCorrespondence)
				.append(this.sentDate).append(this.emails).append(
						this.letterText).append(this.hardCopyDate).append(
						this.corrTypeLkpId).append(this.notes)
						.append(this.complaint).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this)
				.append("complaint", this.complaint)
				.append("corrTypeLkpId", this.corrTypeLkpId)
				.append("letterText", this.letterText)
				.append("generatedDate", this.generatedDate)
				.append("hardCopyDate", this.hardCopyDate)
				.append("emails", this.emails)
				.append("sentDate", this.sentDate)
				.append("title", this.title)
				.append("notes", this.notes)
				.append("id", this.id)
				.append("discardedCorrespondence", this.discardedCorrespondence)
				.toString();
	}

}